package com.qfedu.wfx.manager.controller;

import com.qfedu.wfx.manager.pojos.ParentModule;
import com.qfedu.wfx.manager.pojos.Role;
import com.qfedu.wfx.manager.service.Impl.ModuleServiceImpl;
import com.qfedu.wfx.manager.service.Impl.RoleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("role")
public class RoleController {

    @Autowired
    private RoleServiceImpl roleService;

    @RequestMapping("/list")
    @ResponseBody
    public List<Role> list(){
        return roleService.listRoles();
    }

    @RequestMapping("/listmodules")
    @ResponseBody
    public List<ParentModule> listmodules(String roleId){
        List<ParentModule> parentModules = roleService.listModuleCodesByRoleId(roleId);
        return parentModules;
    }

    @RequestMapping("/grant")
    @ResponseBody
    public void grant(String roleid,String moduleCode){
        roleService.grantModule(roleid,moduleCode);
    }


    @RequestMapping("/del")
    @ResponseBody
    public void delRole(String roleid,String moduleCode){
        roleService.delRole(roleid,moduleCode);
    }
}
